package com.wx.mythread.stopthread;

/**
 * sleep函数catch后会将标志位清除，所以程序还会继续运行
 */
public class CanInterrupted {

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = ()->{
            int num = 0;
            // while (num <= 10000 && !Thread.currentThread().isInterrupted()){
            while (num <= 10000 && !Thread.currentThread().isInterrupted()){
                if (num % 100 == 0 ){
                    System.out.println(num+"是100的倍数");
                }
                num++;
                try {
                    Thread.sleep(10);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
        Thread.sleep(5000);
        thread.interrupt();
    }
}
